package com.henry.db.migrate.main;

import org.apache.log4j.Logger;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestClient {
    private static final Logger logger = Logger.getLogger(TestClient.class);

    public static void main(String[] args) throws Exception {
        logger.info("程序开始运行");
        InitialTables.initTables();
        logger.info("数据库表已经初始化完成...");

        Random random = new Random();
        ExecutorService threadPool = Executors.newFixedThreadPool(30);
        for (int i = 0; i < 200; i++) {
            int seed = random.nextInt(9);
//            seed=seed==0?1:seed;
            for (int j = 0; j <= seed; j++) {
                TestThread thread = new TestThread(InitialTables.tables.get(j));
                threadPool.execute(thread);
            }
        }
        threadPool.shutdown();
        while (true) {
            if (threadPool.isTerminated()) {
                logger.info("全部子线程执行完毕");
                break;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        logger.info("程序运行结束");
    }

}
